<div style="padding: 20px;">
    <div>
        <input type="text" id="fail">
        <a class="layui-btn" data-type="tabAdd" onclick="add()">添加关键词</a>
    </div>
    <table class="layui-table" lay-data="{width: 'full-10', height: 'full-105', url:'/keywords/contenttable?type={{.type}}', page:true}" lay-filter="demo">
        <thead>
        <tr>
            <th lay-data="{field:'id', width:65, fixed: true,sort:true}">Id</th>
            <th lay-data="{field:'keyword',event: 'setSign', width:200}">关键字</th>
            <th lay-data="{field:'score',event: 'setScore', width:200}">评分</th>
            <th lay-data="{field:'hanup',event: 'setHangup', width:250}">是否挂机</th>
            <th lay-data="{fixed:'right', width:200, align:'center', toolbar: '#barTool'}"></th>
        </tr>
        </thead>
    </table>
</div>
<script type="text/html" id="barTool">
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>
<script>
    function add()  {
        if ($("#fail").val() == ""){
             layer.msg("不能为空")
            return
        }
        type_key = {{.type}}
                console.log()
        if  (type_key == 1){
            $.post('{{urlfor "KeywordsController.AjaxSave"}}', "content="+$("#fail").val()+"&type=1", function (out) {
                layer.msg(out.message)
                if (out.status == 0){
                    window.location.reload();
                }
            }, "json");
        }else if (type_key == 2){
            $.post('{{urlfor "KeywordsController.AjaxSave"}}', "content="+$("#fail").val()+"&type=2", function (out) {
                layer.msg(out.message)
                if (out.status == 0){
                    window.location.reload();
                }
            }, "json");
        }else if (type_key == 3){
            $.post('{{urlfor "KeywordsController.AjaxSave"}}', "content="+$("#fail").val()+"&type=3", function (out) {
                layer.msg(out.message)
                if (out.status == 0){
                    window.location.reload();
                }
            }, "json");
        }
    }
    layui.config({
        base : "js/"
    }).use(['table','element','layer','jquery'], function(){
        var table = layui.table;
        var element = layui.element;
        $ = layui.jquery
//监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除【'+data.keyword+'】关键词么', function(index){
                    var jsData = {'id':data.id,'type':"{{.type}}"}
                    $.post('{{urlfor "KeywordsController.AjaxDel"}}', jsData, function (out) {
                        if (out.status == 0) {
                            layer.alert('删除成功了', {icon: 1},function(index){
                                layer.close(index);
                                window.location.reload();
                            });
                        } else {
                            layer.msg(out.message)
                        }
                    }, "json");
                    // obj.del();
                    layer.close(index);
                });
            }else if(obj.event == 'setSign'){
                layer.prompt({
                    formType: 2
                    ,title: '修改关键字'
                    ,value: data.keyword,
                    area:['600px','300px']
                }, function(value,index){
                    layer.close(index)
                    var tabname = ""
                    var type = {{.type}}
                    console.log()
                    if (type  == 1){
                        tabname = "fail_keys"
                    }else if (type  == 2) {
                        tabname = "fine_keys"
                    }else if (type == 3){
                        tabname = "success_keys"
                    }
                    var jsData = "keyword="+value+"&id="+data.id+"&tabname="+tabname;
                    var index = layer.load(2, {time: 10*1000}); //又换了种风格，并且设定最长等待10秒
                    $.post('{{urlfor "KeywordsController.UpdateKeyword"}}', jsData, function (out) {
                        layer.close(index);
                        if (out.status == 0){
                            //同步更新表格和缓存对应的值
                            obj.update({
                                keyword: value
                            });
                        }
                        layer.msg(out.message);
                    }, "json");

                });
            } else if(obj.event == 'setScore'){
                layer.prompt({
                    formType: 2
                    ,title: '修改评分'
                    ,value: data.score,
                    area:['600px','300px']
                }, function(value,index){
                    layer.close(index)
                    var tabname = ""
                    var type = {{.type}}
                    console.log()
                    if (type  == 1){
                        tabname = "fail_keys"
                    }else if (type  == 2) {
                        tabname = "fine_keys"
                    }else if (type == 3){
                        tabname = "success_keys"
                    }
                    var jsData = "score="+value+"&id="+data.id+"&tabname="+tabname;
                    var index = layer.load(2, {time: 10*1000}); //又换了种风格，并且设定最长等待10秒
                    $.post('{{urlfor "KeywordsController.UpdateKeywordScore"}}', jsData, function (out) {
                        layer.close(index);
                        if (out.status == 0){
                            //同步更新表格和缓存对应的值
                            obj.update({
                                score: value
                            });
                        }
                        layer.msg(out.message);
                    }, "json");

                });
            } else if(obj.event == 'setHangup'){
                layer.prompt({
                    formType: 2
                    ,title: '是否强行挂机'
                    ,value: data.hangup,
                    area:['600px','300px']
                }, function(value,index){
                    layer.close(index)
                    var tabname = ""
                    var type = {{.type}}
                    console.log()
                    if (type  == 1){
                        tabname = "fail_keys"
                    }else if (type  == 2) {
                        tabname = "fine_keys"
                    }else if (type == 3){
                        tabname = "success_keys"
                    }
                    var jsData = "auto_hangup="+value+"&id="+data.id+"&tabname="+tabname;
                    var index = layer.load(2, {time: 10*1000}); //又换了种风格，并且设定最长等待10秒
                    $.post('{{urlfor "KeywordsController.UpdateKeywordHangup"}}', jsData, function (out) {
                        layer.close(index);
                        if (out.status == 0){
                            //同步更新表格和缓存对应的值
                            obj.update({
                                hangup: value
                            });
                        }
                        layer.msg(out.message);
                    }, "json");

                });
            }
        });
    });

</script>